package com.atguigu.commonutils.result;

import com.atguigu.commonutils.ResultCodeEnum;
import io.swagger.annotations.ApiModelProperty;

public class BaseResult {

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据内容")
    private Object data;

    private BaseResult() {}

    public static BaseResult success() {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(ResultCode.SUCCESS);
        baseResult.setMessage("操作成功");
        return baseResult;
    }

    public static BaseResult success(String message) {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(ResultCode.SUCCESS);
        baseResult.setMessage(message);
        return baseResult;
    }

    public static BaseResult success(Object data) {
        BaseResult baseResult = new BaseResult();
        baseResult.setData(data);
        baseResult.setMessage("操作成功");
        return baseResult;
    }

    public static BaseResult success(Object data,String message) {
        BaseResult baseResult = new BaseResult();
        baseResult.setData(data);
        baseResult.setMessage(message);
        return baseResult;
    }


    public static BaseResult error(ResultCodeEnum resultCodeEnum) {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(resultCodeEnum.getCode());
        baseResult.setMessage(resultCodeEnum.getMessage());
        return baseResult;
    }

    public static BaseResult error(String message) {
        BaseResult baseResult = new BaseResult();
        baseResult.setCode(ResultCodeEnum.UNKNOWN_REASON.getCode());
        baseResult.setMessage(message);
        return baseResult;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public BaseResult setData(Object data) {
        this.data = data;
        return this;
    }
}
